﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.WebControls;

namespace Shuba.Web.approval_assigment
{
    public partial class pipeline_assignment : basePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string acl = GetUserAccess("ASSIGN_PIPELINE");

                if (!IsUserAdd(acl) && !IsUserEdit(acl))
                {
                    string msg = this.GetGlobalResourceObject("Messages", "NoPrivilege").ToString();
                    AlertAndRedirect(msg, ResolveUrl(ConfigurationManager.AppSettings["default_url"]));
                }

                LabelTitle.Text = GetPageTitle("ASSIGN_PIPELINE");

                BindUserSO();
                Shuba.Business.Pipeline bl = new Shuba.Business.Pipeline();
                Shuba.Model.PipelineInfo bi;

                bi = bl.Get(Request.QueryString["id"]);
                txtFullName.Text = bi.FULL_NAME;
                txtJenisUsaha.Text = bi.JENIS_USAHA;
                txtRencanaPlafon.Text = bi.RENCANA_PLAFON.ToString("n0");
                txtMobilePhone.Text = bi.MOBILE_PHONE;
                txtOfficePhone.Text = bi.OFFICE_PHONE;
                txtResidentialPhone.Text = bi.RESIDENTIAL_PHONE;
                txtKodyaKab.Text = bi.KODYA_KAB_BUSINESS;
                txtKecamatan.Text = bi.KECAMATAN_BUSINESS;
                txtKelurahan.Text = bi.KELURAHAN_BUSINESS;
                txtAlamat.Text = bi.ADDRESS_BUSINESS;
                txtKodePos.Text = bi.ZIP_CODE_BUSINESS;
                txtProspectType.Text = bi.PROSPECT_TYPE;
                txtDebtorType.Text = bi.DEBTOR_TYPE;
                txtChannel.Text = bi.CHANNELING;
            }
        }

        private void BindUserSO()
        {
            Shuba.Business.User bl = new Shuba.Business.User();
            List<Shuba.Model.UserInfo> list = bl.GetUserSO(Session["UnitID"].ToString());
            ddlAO.DataSource = list;
            ddlAO.DataTextField = "Name";
            ddlAO.DataValueField = "UserCode";
            ddlAO.DataBind();

            if (ddlAO.Items.Count > 0)
            {
                ListItem ListAll = new ListItem();
                ListAll.Value = "PILIH";
                ListAll.Text = "- Pilih dengan benar -";
                ddlAO.Items.Insert(0, ListAll);
            }
        }

        protected void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                Shuba.Business.Pipeline bl = new Shuba.Business.Pipeline();
                if (bl.UpdateAssigned(Request.QueryString["id"], ddlAO.SelectedValue, HttpContext.Current.User.Identity.Name) > 0)
                {
                    AddLog("UPDATE", " UPDATE PIPELINE ASSIGNED");
                    AlertAndRedirect("Pipeline sukses diassign", "pipeline_assignment_list.aspx");
                }
            }
            catch (Exception) { }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("pipeline_assignment_list.aspx");
        }
    }
}